package com.mercury.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;


/**
 * @author ：tx
 * @description：spring mvc上下文配置文件
 * @date ：Created in 2019/1/24 19:52
 * @modified By：
 * @version: 1.0
 */
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"com.mercury.controller"})
public class WebConfig extends WebMvcConfigurerAdapter {


    //视图解析器
    @Bean
    public ViewResolver viewResolver(){ //创建视图解析器
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/WEB-INF/home/");
        resolver.setSuffix(".jsp");
        resolver.setExposeContextBeansAsAttributes(true);
        return resolver;
    }

    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }



}
